/*
 * Copyright(C) 2019 FUYUN DATA SERVICES CO.,LTD. - All Rights Reserved
 * Unauthorized copying of this file, via any medium is strictly prohibited
 * Proprietary and confidential
 * 该源代码版权归属福韵数据服务有限公司所有
 * 未经授权，任何人不得复制、泄露、转载、使用，否则将视为侵权
 *
 */

import * as React from "react";
import { connect } from "react-redux";
import { Form, Input, Select, Button } from "antd";

import { FormComponentProps } from "antd/lib/form";

interface IState {
  edit: boolean;
}

interface IProps {
  edit: boolean;
  userData: any;
}

class UserAdd extends React.Component<IProps & FormComponentProps, IState> {
  public state = {
    edit: false
  };

  public handleOk(e: any) {
    e.preventDefault();
    this.props.form.validateFieldsAndScroll((err, values) => {
      if (!err) {
        console.log(values);
      }
    });
  }

  public render() {
    const { getFieldDecorator } = this.props.form;
    return (
      <div style={{ paddingTop: "20px" }}>
        <Form>
          <Form.Item
            label={"用户名"}
            labelCol={{ span: 8 }}
            wrapperCol={{ span: 8 }}
          >
            {getFieldDecorator("account", {
              initialValue: "",
              rules: [
                {
                  required: true,
                  message: "请填写用户名"
                }
              ]
            })(<Input disabled={this.state.edit} />)}
          </Form.Item>
          <Form.Item
            label={"名称"}
            labelCol={{ span: 8 }}
            wrapperCol={{ span: 8 }}
          >
            {getFieldDecorator("name", {
              initialValue: "",
              rules: [
                {
                  required: true,
                  message: "请填写名称"
                }
              ]
            })(<Input disabled={this.state.edit} />)}
          </Form.Item>
          <Form.Item
            label={"密码"}
            labelCol={{ span: 8 }}
            wrapperCol={{ span: 8 }}
          >
            {getFieldDecorator("password", {
              initialValue: "",
              rules: [
                {
                  required: true,
                  message: "请填写密码"
                }
              ]
            })(<Input disabled={this.state.edit} />)}
          </Form.Item>
          <Form.Item
            label={"状态"}
            labelCol={{ span: 8 }}
            wrapperCol={{ span: 8 }}
          >
            {getFieldDecorator("status", {
              initialValue: "0",
              rules: [
                {
                  required: true,
                  message: "请填写密码"
                }
              ]
            })(
              <Select>
                <Select.Option key="0">启用</Select.Option>
                <Select.Option key="1">停用</Select.Option>
              </Select>
            )}
          </Form.Item>
        </Form>

        <div style={{ textAlign: "center" }}>
          <Button type="primary" style={{ marginRight: "20px" }}>
            保存
          </Button>
          {/* <Button type="default">关闭</Button> */}
        </div>
      </div>
    );
  }
}

export default connect()(Form.create<IProps & FormComponentProps>({})(UserAdd));
